package one.bugu.android.demon.ui.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.media.Image;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.github.promeg.pinyinhelper.Pinyin;
import com.juefeng.android.framework.LKUtil;
import com.juefeng.android.framework.common.base.BaseListAdapter;

import java.text.DecimalFormat;
import java.util.List;

import one.bugu.android.demon.R;
import one.bugu.android.demon.bean.BGTInfoBean;
import one.bugu.android.demon.constant.HttpConstant;

/**
 * bgt列表适配
 */
public class BGTInfoAdapter extends BaseListAdapter<BGTInfoBean> {

    private Context context;

    public BGTInfoAdapter(Context context) {
        super(context);
        this.context = context;
    }

    @Override
    public int getContentLayoutId() {
        return R.layout.item_bgtinfo;
    }

    @Override
    public ViewHolder getViewHolder() {
        return new Holder();
    }

    /**
     * 获取所有数据
     *
     * @return
     */
    public List<BGTInfoBean> getAllData() {
        return list;
    }

    public class Holder implements ViewHolder<BGTInfoBean> {

        /**
         * bgt数量
         */
        private TextView bgtNum;

        /**
         * 时间
         */
        private TextView createTime;

        /**
         * 类型
         */
        private TextView tradeTypeName;

        /**
         * 图片类型
         */
        private ImageView typeImg;


        DecimalFormat df = new DecimalFormat("#.#####");

        @Override
        public void initView(View view) {

            bgtNum = view.findViewById(R.id.bgt_num);
            createTime = view.findViewById(R.id.bgt_createTime);
            tradeTypeName = view.findViewById(R.id.bgt_tradeTypeName);
            typeImg = view.findViewById(R.id.bgtType_img);
        }

        @SuppressLint("SetTextI18n")
        @Override
        public void initData(BGTInfoBean bgtInfoBean) {

            //加减标识
            String inOutFlag = bgtInfoBean.getInOutFlag() == 0 ? "+" : "-";
            //名称
            String typeName = Pinyin.toPinyin(bgtInfoBean.getTradeTypeName(), "");
            //文字颜色
            String color = bgtInfoBean.getInOutFlag() == 0 ? "#333333" : "#FE7361";

            //图标
//            LKUtil.getImageLoader().loadImage(String.format(HttpConstant.BASE_IMAGE_URL, typeName), typeImg, R.mipmap.bugu_logo);
            //名称
            tradeTypeName.setText(bgtInfoBean.getTradeTypeName());
            //时间
            createTime.setText(bgtInfoBean.getCreateTime());
            //数量
            bgtNum.setText(inOutFlag + df.format(bgtInfoBean.getOptNum()));
            bgtNum.setTextColor(Color.parseColor(color));


            if ("20".equals(bgtInfoBean.getTradeTypeId())) {
                tradeTypeName.setText("新用户赠送");
                typeImg.setImageResource(R.mipmap.yuyin_zengsong);
            } else if ("10".equals(bgtInfoBean.getTradeTypeId())) {
                tradeTypeName.setText("购买");
                typeImg.setImageResource(R.mipmap.yuyin_chongzhi);
            } else if ("40".equals(bgtInfoBean.getTradeTypeId())) {
                tradeTypeName.setText("使用扣除");
                typeImg.setImageResource(R.mipmap.yuyin_kouchu);
            } else if ("30".equals(bgtInfoBean.getTradeTypeId())) {
                tradeTypeName.setText("邀请奖励");
                typeImg.setImageResource(R.mipmap.yuyin_yaoqing);
            } else if ("50".equals(bgtInfoBean.getTradeTypeId())) {
                tradeTypeName.setText("返还");
                typeImg.setImageResource(R.mipmap.yuyin_fanhuan);
            } else if ("60".equals(bgtInfoBean.getTradeTypeId())) {
                tradeTypeName.setText("签到奖励");
                typeImg.setImageResource(R.mipmap.suanli_denglu);
            } else if ("70".equals(bgtInfoBean.getTradeTypeId())) {
                tradeTypeName.setText(bgtInfoBean.getTradeTypeName());
                typeImg.setImageResource(R.mipmap.bgt_nongchang);
            } else if ("71".equals(bgtInfoBean.getTradeTypeId())) {
                tradeTypeName.setText(bgtInfoBean.getTradeTypeName());
                typeImg.setImageResource(R.mipmap.icon_strike_image);
            } else if ("80".equals(bgtInfoBean.getTradeTypeId())) {
                tradeTypeName.setText(bgtInfoBean.getFlowDesc());
                typeImg.setImageResource(R.mipmap.bgt_duihuan_d);
            } else if ("200".equals(bgtInfoBean.getTradeTypeId())) {
                //购买
                tradeTypeName.setText(bgtInfoBean.getTradeTypeName());
                typeImg.setImageResource(R.mipmap.icon_snatch_items_image);
            } else if ("201".equals(bgtInfoBean.getTradeTypeId())) {
                //夺宝出单失败后bgt返还
                tradeTypeName.setText(bgtInfoBean.getTradeTypeName());
                typeImg.setImageResource(R.mipmap.yuyin_fanhuan);
            } else if ("300".equals(bgtInfoBean.getTradeTypeId())) {
                //eth提现
                tradeTypeName.setText(bgtInfoBean.getTradeTypeName());
                typeImg.setImageResource(R.mipmap.icon_eth_tixian);
            } else if ("301".equals(bgtInfoBean.getTradeTypeId())) {
                //eth提现手续费
                tradeTypeName.setText(bgtInfoBean.getTradeTypeName());
                typeImg.setImageResource(R.mipmap.icon_eth_tixian);
            } else if ("302".equals(bgtInfoBean.getTradeTypeId())) {
                //eth提现返还
                tradeTypeName.setText(bgtInfoBean.getTradeTypeName());
                typeImg.setImageResource(R.mipmap.yuyin_fanhuan);
            } else if ("402".equals(bgtInfoBean.getTradeTypeId())) {
                //版本更新赠送BGT
                tradeTypeName.setText(bgtInfoBean.getTradeTypeName());
                typeImg.setImageResource(R.mipmap.yuyin_zengsong);
            } else if ("303".equals(bgtInfoBean.getTradeTypeId())) {
                //eth提现手续费返还
                tradeTypeName.setText(bgtInfoBean.getTradeTypeName());
                typeImg.setImageResource(R.mipmap.yuyin_fanhuan);
            } else if ("500".equals(bgtInfoBean.getTradeTypeId())) {
                //eth充值
                tradeTypeName.setText(bgtInfoBean.getTradeTypeName());
                typeImg.setImageResource(R.mipmap.yuyin_chongzhi);
            } else if ("501".equals(bgtInfoBean.getTradeTypeId())) {
                //eth消费购买算力
                tradeTypeName.setText(bgtInfoBean.getTradeTypeName());
                typeImg.setImageResource(R.mipmap.icon_magic_cal_icon);
            } else if ("503".equals(bgtInfoBean.getTradeTypeId())) {
                //购买魔法算力赠送BGT
                tradeTypeName.setText(bgtInfoBean.getTradeTypeName());
                typeImg.setImageResource(R.mipmap.yuyin_zengsong);
            } else if ("504".equals(bgtInfoBean.getTradeTypeId())) {
                //购买魔法算力首充赠送BGT
                tradeTypeName.setText(bgtInfoBean.getTradeTypeName());
                typeImg.setImageResource(R.mipmap.yuyin_zengsong);
            } else if ("504".equals(bgtInfoBean.getTradeTypeId())) {
                //购买魔法算力首充赠送BGT
                tradeTypeName.setText(bgtInfoBean.getTradeTypeName());
                typeImg.setImageResource(R.mipmap.yuyin_zengsong);
            } else if ("505".equals(bgtInfoBean.getTradeTypeId())) {
                //算力头衔奖励
                tradeTypeName.setText(bgtInfoBean.getFlowDesc());
                typeImg.setImageResource(R.mipmap.yuyin_zengsong);
            } else if ("600".equals(bgtInfoBean.getTradeTypeId())) {
                //财务加款
                tradeTypeName.setText(bgtInfoBean.getTradeTypeName());
                typeImg.setImageResource(R.mipmap.icon_snatch_items_image);
            } else if ("601".equals(bgtInfoBean.getTradeTypeId())) {
                //财务减款
                tradeTypeName.setText(bgtInfoBean.getTradeTypeName());
                typeImg.setImageResource(R.mipmap.icon_eth_tixian);
            } else {
                tradeTypeName.setText(bgtInfoBean.getTradeTypeName());
                typeImg.setImageResource(R.mipmap.yuyin_zengsong);
            }

        }

        @Override
        public void initEvent(BGTInfoBean bgtInfoBean) {

        }
    }
}
